package logic

import (
	"context"
	"doc-manage/doctorrpc/doctorrpc"
	"doc-manage/doctorrpc/internal/svc"
	"doc-manage/models/mysql"
	"errors"

	"github.com/zeromicro/go-zero/core/logx"
)

type DoctorAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewDoctorAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DoctorAddLogic {
	return &DoctorAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 添加方法
func (l *DoctorAddLogic) DoctorAdd(in *doctorrpc.DoctorAddRequest) (*doctorrpc.DoctorAddResponse, error) {
	// todo: add your logic here and delete this line

	doctor := mysql.Doctor{
		DoctorName:  in.DoctorName,
		DoctorImage: in.DoctorImage,
	}

	err := doctor.DoctorAdd(mysql.DB)
	if err != nil {
		return nil, errors.New("添加失败")
	}

	return &doctorrpc.DoctorAddResponse{
		DoctorId: int64(doctor.ID),
	}, nil
}
